<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <el-card>
      <el-table :data="rightsList"
                style="width:100%"
                border
                stripe>
        <el-table-column type='index'
                         label="#"></el-table-column>
        <el-table-column prop='authName'
                         label="权限名称"></el-table-column>
        <el-table-column prop='path'
                         label="路径"></el-table-column>
        <el-table-column prop='level'
                         label="级别">
          <template slot-scope="data">
            <el-tag v-if="data.row.level == 0">一级</el-tag>
            <el-tag type="success"
                    v-else-if="data.row.level == 1">二级</el-tag>
            <el-tag type="danger"
                    v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  // 钩子函数:当 配置对象 成员都挂载到当前实例对象后执行
  created () {
    // a. 发送请求 所有权限列表 接口
    this.getRightsList()
  },
  data () {
    return {
      rightsList: []
    }
  },
  methods: {
    // 请求 权限列表
    async getRightsList () {
      // 请求数据
      const { data: resData } = await this.$http.get('rights/list')
      // 判断
      if (resData.meta.status !== 200) return this.$message.error(resData.meta.msg)
      // 如果成功,则设置 resData.data 中的权限数组 给 实例.data
      this.rightsList = resData.data
    }
  }
}
</script>

<style lang="less" scoped>
</style>
